package com.foodlocker.maintenance;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.Button;

import com.foodlocker.machine.R;

public class ConfigAct extends FragmentActivity {
	Fragment synchroData_fragment;
	Fragment network_cng_fragment;
	View.OnClickListener myListener;
	Button  btn_recovery,btn_netcfg;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_machine_config);
		synchroData_fragment= new SynchroDataFragment();
		 network_cng_fragment= new NetworkConfigFragment();
		 define_myListener();	
		 btn_recovery= (Button) findViewById(R.id.btn_recovery_act_cfg);
		 btn_netcfg=(Button) findViewById(R.id.btn_net_act_cfg);
		 btn_netcfg.setOnClickListener(myListener);
		 btn_recovery.setOnClickListener(myListener);
		 Intent intent = getIntent();
		 showFragment(intent.getFlags());
	     
		 }
		
	private void define_myListener(){
		myListener=new View.OnClickListener() {
		
			@Override
			public void onClick(View v) {
				if(v.getId()==R.id.btn_net_act_cfg) showFragment(1);
				if(v.getId()==R.id.btn_recovery_act_cfg) showFragment(2);
				
			}
		};
		
	}	
	
	
	private void showFragment(int flag){
		switch(flag){
		case 2: {
			   FragmentManager fragmentManager = getSupportFragmentManager();
		       FragmentTransaction  transaction = fragmentManager.beginTransaction();	      
			   transaction.replace(R.id.container_act_cng,  synchroData_fragment).commit();
			
		       }
		case 1: {
					 FragmentManager fragmentManager = getSupportFragmentManager();
				       FragmentTransaction  transaction = fragmentManager.beginTransaction();	      
					   transaction.replace(R.id.container_act_cng,  network_cng_fragment).commit();
				       }
		}
	}
}
